package com.zxy.controller;

import com.zxy.common.result.Result;
import com.zxy.pojo.dto.RoleDTO;
import com.zxy.pojo.dto.RoleQueryDTO;
import com.zxy.pojo.dto.SystempageDTO;
import com.zxy.pojo.dto.UserAddDTO;
import com.zxy.pojo.entity.SysRole;
import com.zxy.pojo.entity.SysUser;
import com.zxy.pojo.vo.CourseContractResponseVO;
import com.zxy.service.SysUserService;
import com.zxy.util.OperLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class SystemUserController {

    @Autowired
    private SysUserService sysUserService;


    /**
     * 根据部门ID查询用户列表
     * @param deptId 部门ID
     * @return 用户列表
     */
    @OperLog(title = "根据部门ID查询用户列表",businessType = 0,saveParams = true,saveResult = true)
    @GetMapping("/system/user/listselect")
    public Result<List<SysUser>> getUserListByDeptId(@RequestParam("deptId") Long deptId) {
        List<SysUser> userList = sysUserService.getUserListByDeptId(deptId);
        return Result.success(userList);
    }

    //用户管理列表
    @OperLog(title = "用户管理列表",businessType = 0,saveParams = true,saveResult = true)
    @GetMapping("/system/user/list")
    public CourseContractResponseVO<SysUser> getUserList(SystempageDTO dto){
         return sysUserService.getUserList(dto);
    }

    //用户名称展示
    @OperLog(title = "用户名称展示",businessType = 0,saveParams = true,saveResult = true)
    @GetMapping("/system/user/")
    public Map<String,Object> getRoles() {
        List<RoleDTO> roleDTOS = sysUserService.listRoles();
        Map<String, Object> resultMap = new HashMap<>(3);
        resultMap.put("code", 200);
        resultMap.put("msg", "操作成功");
        resultMap.put("roles", roleDTOS);
        return resultMap;
    }

    //添加用户
    @OperLog(title = "添加用户",businessType = 0,saveParams = true,saveResult = false)
    @PostMapping("/system/user")
    public Result addUser(@RequestBody UserAddDTO userDTO) {
        sysUserService.addUser(userDTO);
        return Result.success();
    }

    //TODO 其他的删除修改添加没有写
    //根据id回显用户信息
    @OperLog(title = "根据id回显用户信息",businessType = 0)
    @GetMapping("/user/{userid}")
    public Result getUserById(@PathVariable("userid") Long userid) {
        return null;
    }

    //查询角色
    @OperLog(title = "查询角色",businessType = 0)
    @GetMapping("/system/role/list")
    public CourseContractResponseVO<SysRole> getRoleList(RoleQueryDTO dto) {
          return sysUserService.getRoleList(dto);
    }
}